package com.ejoysoft.wlanyz.business;

import com.ejoysoft.common.DbConnect;
import com.ejoysoft.common.Globa;
import com.ejoysoft.wlanyz.system.User;
import com.sun.crypto.provider.RSACipher;

import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Vector;


public class ResultsShow {

    private Globa globa;
    private DbConnect db;

    //构造方法
    public ResultsShow() {
    }

    public ResultsShow(Globa globa) {
        this.globa = globa;
        db = globa.db;
    }

    //构造方法 
    public ResultsShow(Globa globa, boolean b) {
        this.globa = globa;
        db = globa.db;
        if (b) globa.setDynamicProperty(this);
    }
    
    private String strTableName = "wlan_test_result";
    private String strTableName2 = "WLAN_RESC_COMUNITY";
    private String strTableName3 = "WLAN_TASK_INFO";
    
    //列表记录集
    public ResultsShow load(ResultSet rs ) throws SQLException{
    	ResultsShow theBean = new ResultsShow();
        try {
            theBean.setStrId(rs.getString("strId"));
            theBean.setStrTaskId(rs.getString("strTaskId"));
            theBean.setStrTaskName(rs.getString("strTaskName"));
            theBean.setStrCity(rs.getString("strCity"));
            theBean.setStrTown(rs.getString("strTown"));
            theBean.setStrNetType(rs.getString("strNetType"));
            theBean.setStrLac(rs.getString("strlac"));
            theBean.setStrSiteName(rs.getString("strSiteName"));
            theBean.setStrCommunityId(rs.getString("strci"));
            theBean.setStrTaskType(rs.getString("strTaskType"));
            theBean.setStrTaskMan(rs.getString("strTaskMan"));
            theBean.setStrPhone(rs.getString("strtaskphone"));
            theBean.setDtCreateDate(rs.getString("dtCreatDate"));
            theBean.setINTAP_RELEVACY_SUCRATE(rs.getDouble("INTAP_RELEVACY_SUCRATE"));
            theBean.setINTAP_RELEVACY_DELAY(rs.getDouble("INTAP_RELEVACY_DELAY"));
            theBean.setINTWEB_AUTH_SUCRATE(rs.getDouble("INTWEB_AUTH_SUCRATE"));
            theBean.setINTWEB_OFF_SUCRATE(rs.getDouble("INTWEB_OFF_SUCRATE"));
            theBean.setINTPEAP_AUTH_SUCRATE(rs.getDouble("INTPEAP_AUTH_SUCRATE"));
            theBean.setINTPEAP_OFF_SUCRATE(rs.getDouble("INTPEAP_OFF_SUCRATE"));
            theBean.setINTHTTP_REQ_SUCRATE(rs.getDouble("INTHTTP_REQ_SUCRATE"));
            theBean.setINTPING_SUCRATE(rs.getDouble("INTPING_SUCRATE"));
            theBean.setINTFTP_UP_SUCRATE(rs.getDouble("INTFTP_UP_SUCRATE"));
            theBean.setINTFTP_DOWN_SUCRATE(rs.getDouble("INTFTP_DOWN_SUCRATE"));
            theBean.setINTUSER_SEG_SUCRATE(rs.getDouble("INTUSER_SEG_SUCRATE"));
            theBean.setINTUSER_ROAM_SUCRATE(rs.getDouble("INTUSER_ROAM_SUCRATE"));
            theBean.setINTWEB_UP_DELAY(rs.getDouble("INTWEB_UP_DELAY"));
            theBean.setINTWEB_DOWN_DELAY(rs.getDouble("INTWEB_DOWN_DELAY"));
            theBean.setINTPEAP_UP_DELAY(rs.getDouble("INTPEAP_UP_DELAY"));
            theBean.setINTHTTP_RESP_DELAY(rs.getDouble("INTHTTP_RESP_DELAY"));
            theBean.setINTPING_DELAY(rs.getDouble("INTPING_DELAY"));
            theBean.setINTFTP_UP_SPEED(rs.getDouble("INTFTP_UP_SPEED"));
            theBean.setINTFTP_DOWN_SPEED(rs.getDouble("INTFTP_DOWN_SPEED"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return theBean;
    }
    //查询符合条件的记录�?�数
    public int getCount(String where,String strStartTime ,String strEndTime) throws SQLException{
        int count = 0;
        try {
        	if(strStartTime.equals(""))strStartTime = "1000-1-01";
            if(strEndTime.equals(""))strEndTime = "9999-12-30";
            String timeWhere = " and a.DTCREATDATE  between to_date('" + strStartTime + "','yyyy-MM-dd hh24.mi.ss') and to_date('" + strEndTime + "','yyyy-MM-dd hh24.mi.ss')" ; 
            String sql = "SELECT count(*) FROM " + strTableName + " a left join " + strTableName2 + " b  on  a.strcommunityid = b.strcommid left join " + strTableName3 + " c on a.strtaskid = c.strtaskid ";
            if (where.length() > 0) {
                where = where.toLowerCase();
                if (where.indexOf("order") > 0)
                    where = where.substring(0, where.indexOf("order"));
                sql = String.valueOf(sql) + String.valueOf(where)+ String.valueOf(timeWhere);
            }
            ResultSet rs = db.executeQuery(sql);
            if (rs.next())
                count = rs.getInt(1);
            rs.close();
            return count;
        } catch (Exception ee) {
            ee.printStackTrace();
            return count;
        }
    }
    
    //拿到任务的19条指标
    public ResultsShow show(String where){
    	ResultsShow showBean=null;
    	try { 
    		String sql = "select INTAP_RELEVACY_SUCRATE,INTAP_RELEVACY_DELAY,INTWEB_AUTH_SUCRATE,INTWEB_OFF_SUCRATE,INTPEAP_AUTH_SUCRATE,INTPEAP_OFF_SUCRATE," +
    				"INTHTTP_REQ_SUCRATE,INTPING_SUCRATE,INTFTP_UP_SUCRATE,INTFTP_DOWN_SUCRATE,INTUSER_SEG_SUCRATE,INTUSER_ROAM_SUCRATE,INTWEB_UP_DELAY," +
    				"INTWEB_DOWN_DELAY,INTPEAP_UP_DELAY,INTHTTP_RESP_DELAY,INTPING_DELAY,INTFTP_UP_SPEED,INTFTP_DOWN_SPEED from " + strTableName + " ";
			sql = String.valueOf(sql) + String.valueOf(where);
			Statement statement = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
			ResultSet rs = db.executeQuery(sql);
			 if (rs != null && rs.next()){
				 showBean=load1(rs, true);
			 }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return showBean;
    }
    
    //记录集转化为对象
    public ResultsShow load1(ResultSet rs, boolean isView) {
    	ResultsShow theBean = new ResultsShow();
        try {
        	theBean.setINTAP_RELEVACY_SUCRATE(rs.getDouble("INTAP_RELEVACY_SUCRATE"));
            theBean.setINTAP_RELEVACY_DELAY(rs.getDouble("INTAP_RELEVACY_DELAY"));
            theBean.setINTWEB_AUTH_SUCRATE(rs.getDouble("INTWEB_AUTH_SUCRATE"));
            theBean.setINTWEB_OFF_SUCRATE(rs.getDouble("INTWEB_OFF_SUCRATE"));
            theBean.setINTPEAP_AUTH_SUCRATE(rs.getDouble("INTPEAP_AUTH_SUCRATE"));
            theBean.setINTPEAP_OFF_SUCRATE(rs.getDouble("INTPEAP_OFF_SUCRATE"));
            theBean.setINTHTTP_REQ_SUCRATE(rs.getDouble("INTHTTP_REQ_SUCRATE"));
            theBean.setINTPING_SUCRATE(rs.getDouble("INTPING_SUCRATE"));
            theBean.setINTFTP_UP_SUCRATE(rs.getDouble("INTFTP_UP_SUCRATE"));
            theBean.setINTFTP_DOWN_SUCRATE(rs.getDouble("INTFTP_DOWN_SUCRATE"));
            theBean.setINTUSER_SEG_SUCRATE(rs.getDouble("INTUSER_SEG_SUCRATE"));
            theBean.setINTUSER_ROAM_SUCRATE(rs.getDouble("INTUSER_ROAM_SUCRATE"));
            theBean.setINTWEB_UP_DELAY(rs.getDouble("INTWEB_UP_DELAY"));
            theBean.setINTWEB_DOWN_DELAY(rs.getDouble("INTWEB_DOWN_DELAY"));
            theBean.setINTPEAP_UP_DELAY(rs.getDouble("INTPEAP_UP_DELAY"));
            theBean.setINTHTTP_RESP_DELAY(rs.getDouble("INTHTTP_RESP_DELAY"));
            theBean.setINTPING_DELAY(rs.getDouble("INTPING_DELAY"));
            theBean.setINTFTP_UP_SPEED(rs.getDouble("INTFTP_UP_SPEED"));
            theBean.setINTFTP_DOWN_SPEED(rs.getDouble("INTFTP_DOWN_SPEED"));

        } catch (Exception e) {
            e.printStackTrace();
        }
        return theBean;
    }

    
  //列表记录
    public Vector<ResultsShow> list(String where, int startRow, int rowCount ,String strStartTime ,String strEndTime) throws SQLException{
        Vector<ResultsShow> beans = new Vector<ResultsShow>();
        try {
        	 if(strStartTime.equals(""))strStartTime = "1000-1-01";
             if(strEndTime.equals(""))strEndTime = "9999-12-30";
             
             String timeWhere = " and a.DTCREATDATE  between to_date('" + strStartTime + "','yyyy-MM-dd hh24.mi.ss') and to_date('" + strEndTime + "','yyyy-MM-dd hh24.mi.ss')" ; 

            String sql = "SELECT a.*, b.strcity ,b.strtown,b.strsitename,b.strlac,b.strci,c.strtaskphone,c.strTaskMan,c.strtasktype,c.strtaskname  FROM   " 
            	+ strTableName + " a left join " + strTableName2 + " b  on  a.strcommunityid = b.strcommid left join " + strTableName3 + " c on a.strtaskid = c.strtaskid ";
            sql = String.valueOf(sql) + String.valueOf(where)+String.valueOf(timeWhere) ;//
            System.err.println(sql+"lllllllllllllllllllllllll");
            Statement s = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            if (startRow != 0 && rowCount != 0)
                s.setMaxRows((startRow + rowCount) - 1);
            ResultSet rs = s.executeQuery(sql);
            if (rs != null && rs.next()) {
                if (startRow != 0 && rowCount != 0)
                    rs.absolute(startRow);
                do {
                	ResultsShow theBean = new ResultsShow();
                    theBean = load(rs);
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
            s.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        return beans;
    } 

  
    //调出所有地市名称
    public ArrayList<String> getAllCitiesByName( String where)
    {
    	//System.err.println(where+"=========");
    	ArrayList<String>  beans = new ArrayList<String>();
    	String sql = "select distinct(b.strCity) from "+ strTableName + " a left join " + strTableName2 + " b on a.strcommunityid = b.strcommid left join " + strTableName3 + " c on a.strtaskid = c.strtaskid ";
    	if(where!=null && where.length()>0)
    		sql = sql +" "+where;
    	//System.err.println(sql+"=========");
    	ResultSet re = db.executeQuery(sql);
    	try {
    	
			if(re != null && re.next())
			{   //String country = re.getString("");
				do{
					String city = re.getString("strCity");
					beans.add(city);
				}while(re.next());
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return beans;
    }
    //拿到目录下的所有文件详细路径
    public Vector<String> showAllFiles(File dir) throws Exception{
    	Vector<String> filePath = new Vector<String>();
    	  File[] fs = dir.listFiles();
    	  for(int i=0; i<fs.length; i++){
    	   //System.out.println(fs[i].getAbsolutePath());
    		  filePath.add(fs[i].getAbsolutePath());
    	   if(fs[i].isDirectory()){
    	    try{
    	     showAllFiles(fs[i]);
    	    }catch(Exception e){}
    	   }
    	  }
    	  return filePath;
    	 }
    
    private String strId;//标记字段
    private String strTaskId;//任务id
    private String strTaskName;//任务名
    private String strTaskType;//任务类型
    private String strNetType;//网络类型
    private String strCity;//地市
    private String strTown;//区县
    private String strMac;//Mac地址
    private String strCommunityId;//小区Id
    private String strLac;//小区区码
    private String strSiteName;//小区区码
	private String dtCreateDate;//时间
	private String strTaskMan;//结束时间
    private String strPhone;//结束时间
    private double INTAP_RELEVACY_SUCRATE;//AP关联成功率
    private double INTAP_RELEVACY_DELAY;//AP关联时延
    private double INTWEB_AUTH_SUCRATE;//WEB认证成功率
    private double INTWEB_OFF_SUCRATE;//WEB下线成功率
    private double INTPEAP_AUTH_SUCRATE;//PEAP认证成功率
    private double INTPEAP_OFF_SUCRATE;//PEAP下线成功率
    private double INTHTTP_REQ_SUCRATE;//HTTP请求成功率
    private double INTPING_SUCRATE;//PING成功率
    private double INTFTP_UP_SUCRATE;//FTP上行成功率
    private double INTFTP_DOWN_SUCRATE;//FTP下行成功率
    private double INTUSER_SEG_SUCRATE;//用户隔离成功率
    private double INTUSER_ROAM_SUCRATE;//用户漫游成功率
    private double INTWEB_UP_DELAY;//WEB认证时延
    private double INTWEB_DOWN_DELAY;//WEB下线时延
    private double INTPEAP_UP_DELAY;//PEAP认证时延
    private double INTHTTP_RESP_DELAY;//HTTP响应时延
    private double INTPING_DELAY;//PING平均时延
    private double INTFTP_UP_SPEED;//FTP上行速率
    private double INTFTP_DOWN_SPEED;//FTP下行速率
    
    
    
	public String getDtCreateDate() {
		return dtCreateDate;
	}

	public void setDtCreateDate(String dtCreateDate) {
		this.dtCreateDate = dtCreateDate;
	}

	public String getStrPhone() {
		return strPhone;
	}

	public void setStrPhone(String strPhone) {
		this.strPhone = strPhone;
	}

	public String getStrSiteName() {
		return strSiteName;
	}

	public void setStrSiteName(String strSiteName) {
		this.strSiteName = strSiteName;
	}
	
    public String getStrTaskType() {
		return strTaskType;
	}

	public void setStrTaskType(String strTaskType) {
		this.strTaskType = strTaskType;
	}

	public String getStrId() {
		return strId;
	}

	public void setStrId(String strId) {
		this.strId = strId;
	}

	public String getStrTaskId() {
		return strTaskId;
	}

	public void setStrTaskId(String strTaskId) {
		this.strTaskId = strTaskId;
	}

	public String getStrTaskName() {
		return strTaskName;
	}

	public void setStrTaskName(String strTaskName) {
		this.strTaskName = strTaskName;
	}

	public String getStrNetType() {
		return strNetType;
	}

	public void setStrNetType(String strNetType) {
		this.strNetType = strNetType;
	}

	public String getStrCity() {
		return strCity;
	}

	public void setStrCity(String strCity) {
		this.strCity = strCity;
	}

	public String getStrTown() {
		return strTown;
	}

	public void setStrTown(String strTown) {
		this.strTown = strTown;
	}

	public String getStrMac() {
		return strMac;
	}

	public void setStrMac(String strMac) {
		this.strMac = strMac;
	}

	public String getStrCommunityId() {
		return strCommunityId;
	}

	public void setStrCommunityId(String strCommunityId) {
		this.strCommunityId = strCommunityId;
	}
	
	public String getStrLac() {
		return strLac;
	}

	public void setStrLac(String strLac) {
		this.strLac = strLac;
	}

	public String getStrTaskMan() {
		return strTaskMan;
	}

	public void setStrTaskMan(String strTaskMan) {
		this.strTaskMan = strTaskMan;
	}

	public double getINTAP_RELEVACY_SUCRATE() {
		return INTAP_RELEVACY_SUCRATE;
	}

	public void setINTAP_RELEVACY_SUCRATE(double iNTAPRELEVACYSUCRATE) {
		INTAP_RELEVACY_SUCRATE = iNTAPRELEVACYSUCRATE;
	}

	public double getINTAP_RELEVACY_DELAY() {
		return INTAP_RELEVACY_DELAY;
	}

	public void setINTAP_RELEVACY_DELAY(double iNTAPRELEVACYDELAY) {
		INTAP_RELEVACY_DELAY = iNTAPRELEVACYDELAY;
	}

	public double getINTWEB_AUTH_SUCRATE() {
		return INTWEB_AUTH_SUCRATE;
	}

	public void setINTWEB_AUTH_SUCRATE(double iNTWEBAUTHSUCRATE) {
		INTWEB_AUTH_SUCRATE = iNTWEBAUTHSUCRATE;
	}

	public double getINTWEB_OFF_SUCRATE() {
		return INTWEB_OFF_SUCRATE;
	}

	public void setINTWEB_OFF_SUCRATE(double iNTWEBOFFSUCRATE) {
		INTWEB_OFF_SUCRATE = iNTWEBOFFSUCRATE;
	}

	public double getINTPEAP_AUTH_SUCRATE() {
		return INTPEAP_AUTH_SUCRATE;
	}

	public void setINTPEAP_AUTH_SUCRATE(double iNTPEAPAUTHSUCRATE) {
		INTPEAP_AUTH_SUCRATE = iNTPEAPAUTHSUCRATE;
	}

	public double getINTPEAP_OFF_SUCRATE() {
		return INTPEAP_OFF_SUCRATE;
	}

	public void setINTPEAP_OFF_SUCRATE(double iNTPEAPOFFSUCRATE) {
		INTPEAP_OFF_SUCRATE = iNTPEAPOFFSUCRATE;
	}

	public double getINTHTTP_REQ_SUCRATE() {
		return INTHTTP_REQ_SUCRATE;
	}

	public void setINTHTTP_REQ_SUCRATE(double iNTHTTPREQSUCRATE) {
		INTHTTP_REQ_SUCRATE = iNTHTTPREQSUCRATE;
	}

	public double getINTPING_SUCRATE() {
		return INTPING_SUCRATE;
	}

	public void setINTPING_SUCRATE(double iNTPINGSUCRATE) {
		INTPING_SUCRATE = iNTPINGSUCRATE;
	}

	public double getINTFTP_UP_SUCRATE() {
		return INTFTP_UP_SUCRATE;
	}

	public void setINTFTP_UP_SUCRATE(double iNTFTPUPSUCRATE) {
		INTFTP_UP_SUCRATE = iNTFTPUPSUCRATE;
	}

	public double getINTFTP_DOWN_SUCRATE() {
		return INTFTP_DOWN_SUCRATE;
	}

	public void setINTFTP_DOWN_SUCRATE(double iNTFTPDOWNSUCRATE) {
		INTFTP_DOWN_SUCRATE = iNTFTPDOWNSUCRATE;
	}

	public double getINTUSER_SEG_SUCRATE() {
		return INTUSER_SEG_SUCRATE;
	}

	public void setINTUSER_SEG_SUCRATE(double iNTUSERSEGSUCRATE) {
		INTUSER_SEG_SUCRATE = iNTUSERSEGSUCRATE;
	}

	public double getINTUSER_ROAM_SUCRATE() {
		return INTUSER_ROAM_SUCRATE;
	}

	public void setINTUSER_ROAM_SUCRATE(double iNTUSERROAMSUCRATE) {
		INTUSER_ROAM_SUCRATE = iNTUSERROAMSUCRATE;
	}

	public double getINTWEB_UP_DELAY() {
		return INTWEB_UP_DELAY;
	}

	public void setINTWEB_UP_DELAY(double iNTWEBUPDELAY) {
		INTWEB_UP_DELAY = iNTWEBUPDELAY;
	}

	public double getINTWEB_DOWN_DELAY() {
		return INTWEB_DOWN_DELAY;
	}

	public void setINTWEB_DOWN_DELAY(double iNTWEBDOWNDELAY) {
		INTWEB_DOWN_DELAY = iNTWEBDOWNDELAY;
	}

	public double getINTPEAP_UP_DELAY() {
		return INTPEAP_UP_DELAY;
	}

	public void setINTPEAP_UP_DELAY(double iNTPEAPUPDELAY) {
		INTPEAP_UP_DELAY = iNTPEAPUPDELAY;
	}

	public double getINTHTTP_RESP_DELAY() {
		return INTHTTP_RESP_DELAY;
	}

	public void setINTHTTP_RESP_DELAY(double iNTHTTPRESPDELAY) {
		INTHTTP_RESP_DELAY = iNTHTTPRESPDELAY;
	}

	public double getINTPING_DELAY() {
		return INTPING_DELAY;
	}

	public void setINTPING_DELAY(double iNTPINGDELAY) {
		INTPING_DELAY = iNTPINGDELAY;
	}

	public double getINTFTP_UP_SPEED() {
		return INTFTP_UP_SPEED;
	}

	public void setINTFTP_UP_SPEED(double iNTFTPUPSPEED) {
		INTFTP_UP_SPEED = iNTFTPUPSPEED;
	}

	public double getINTFTP_DOWN_SPEED() {
		return INTFTP_DOWN_SPEED;
	}

	public void setINTFTP_DOWN_SPEED(double iNTFTPDOWNSPEED) {
		INTFTP_DOWN_SPEED = iNTFTPDOWNSPEED;
	}


	
}